//
//  PhotoToolBottomBar.m
//  WOFishingBoat
//
//  Created by 郑逸凯 on 2019/1/8.
//  Copyright © 2019年 郑逸凯. All rights reserved.
//

#import "PhotoToolBottomBar.h"

@interface PhotoToolBottomBar ()
@property (nonatomic,strong)UIButton *deleteButton;
@property (nonatomic,strong)UIButton *downloadButton;
@end

@implementation PhotoToolBottomBar

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = RGB16(0xffffff);
        [self addSubview:self.deleteButton];
        [self addSubview:self.downloadButton];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat width = self.frame.size.width;
    CGFloat height = self.frame.size.height;
    CGFloat btn_width = 40;
    self.downloadButton.frame = CGRectMake(10, (height -btn_width)/2, btn_width, btn_width);
    self.deleteButton.frame = CGRectMake(width - btn_width-10, (height -btn_width)/2, btn_width, btn_width);
}

- (void)deleteAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(deleteClickedPhotoToolBottomBar:)]) {
        [self.delegate deleteClickedPhotoToolBottomBar:self];
    }
}

- (void)downloadAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(downloadClickedPhotoToolBottomBar:)]) {
        [self.delegate downloadClickedPhotoToolBottomBar:self];
    }
}

- (UIButton *)deleteButton {
    if (!_deleteButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0, 0, 40, 40);
        [button setImage:[UIImage imageNamed:@"alb_del"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside];
        _deleteButton = button;
    }
    return _deleteButton;
}

- (UIButton *)downloadButton {
    if (!_downloadButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0, 0, 40, 40);
        [button setImage:[UIImage imageNamed:@"alb_download"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(downloadAction) forControlEvents:UIControlEventTouchUpInside];
        _downloadButton = button;
    }
    return _downloadButton;
}


@end
